Use case: FastTake/ReleaseAll all semaphores at once with correct Key ¶
This use case shows how the application sets a clear key, takes multiple semaphores using the fast-take mechanism, then releases all semaphores associated with the current core in a single operation.
Sequence diagram ¶
Code snippet ¶
|
HAL1 |
HAL2 |
|---|---|
uint32_t clear_key;
uint32_t sem_state0, sem_state1;
#define HSEM_ID_0 (0U) /* HW semaphore 0*/
#define HSEM_ID_1 (1U) /* HW semaphore 1*/
/* HW semaphore Clock enable */
__HAL_RCC_HSEM_CLK_ENABLE() ;
HAL_HSEM_SetClearKey(clear_key);
HAL_HSEM_FastTake(HSEM_ID_0);
HAL_HSEM_FastTake(HSEM_ID_1);
clear_key = HAL_HSEM_GetClearKey();
HAL_HSEM_ReleaseAll(clear_key, 1U);
sem_state0 = HAL_HSEM_IsSemTaken(HSEM_SEM_0);
sem_state1 = HAL_HSEM_IsSemTaken(HSEM_SEM_1);
if ((sem_state0 == 0U) && (sem_state1 == 0U))
{
/* Both hardware semaphores are released */
}
|
uint32_t clear_key;
hal_hsem_status_t sem_state0, sem_state1;
/* HW semaphore Clock enable */
HAL_RCC_HSEM_EnableClock();
HAL_HSEM_SetClearKey(clear_key);
HAL_HSEM_FastTake(HAL_HSEM_0);
HAL_HSEM_FastTake(HAL_HSEM_1);
clear_key = HAL_HSEM_GetClearKey();
HAL_HSEM_ReleaseAll(clear_key, HAL_HSEM_LOCKID_CURRENT_CPU);
sem_state0 = HAL_HSEM_IsTaken(HAL_HSEM_0);
sem_state1 = HAL_HSEM_IsTaken(HAL_HSEM_1);
if ((sem_state0 == HAL_HSEM_RELEASED) && (sem_state1 == HAL_HSEM_RELEASED))
{
/* Both hardware semaphores are released */
}
|

